"books":[<?php $nb = count($history); $i = 0; foreach ($history as $id => $book): ++$i ?>
{ "id": "<?php echo $id ?>", <?php $nb1 = count($book); $j = 0; foreach ($book as $key => $value): ++$j ?>"<?php echo $key ?>": <?php echo json_encode($value).($nb1 == $j ? '' : ',') ?><?php endforeach ?> }<?php echo $nb == $i ? '' : ',' ?>
<?php endforeach ?>
]